package lm.concurrency.day5.atomicReference.atomicReferenceFieldUpdater;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
 * @Auther: Min.Liu
 * @Description:
 * @Date: Created in 15:38 2024/11/7
 */
public class AtomicUpdateDemo {
    public static void main(String[] args) {
        AtomicReferenceFieldUpdater<Student, String> updater =
                AtomicReferenceFieldUpdater.newUpdater(Student.class, String.class, "name");
        Student stu = new Student();
        updater.compareAndSet(stu, null, "liumin");
        System.out.println(stu);
        boolean res1 = updater.compareAndSet(stu, "liumin", "limengli");
        System.out.println("替换结果:"+res1+"====>"+stu);
        boolean res2 = updater.compareAndSet(stu, "liumin", "liuting");
        System.out.println("替换结果:"+res2+"====>"+stu);
    }
}


